package backTracing;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class 全排列 {

    public static void main(String[] args) {

    }



    List<List<Integer>> res=new ArrayList<>();
    LinkedList<Integer> list=new LinkedList<>();
    boolean[] used;
    public List<List<Integer>> permute(int[] nums) {
        used=new boolean[nums.length];
        backtracking(nums,used);
        return res;
    }

    public void backtracking(int[] nums,boolean[] used){
        for(int i=0;i<nums.length;i++){
            if(list.size()==nums.length){
                res.add(new ArrayList(list));
                return;
            }
            if(used[i]==true)
                continue;
            list.add(nums[i]);
            used[i]=true;
            backtracking(nums,used);
            used[i]=false;
            list.removeLast();
        }
    }
}
